import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:material_collection_app/utils/utils.dart';

class DrawerGrid extends StatefulWidget {
  final String title;

  DrawerGrid({
    Key key,
    this.title
  })
  : super(key: key);

  @override
  State<StatefulWidget> createState() => MyState();
}

class MyState extends State<DrawerGrid> {

  Widget _buildCardLine() {
    return Container(
      width: double.infinity,
      height: 1,
      margin: EdgeInsets.symmetric(vertical: 29.w),
      color: Utils.hexToColor('#FBFBFB'),
    );
  }

  Widget _buildCardTitle(title) {
    return Container(
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.only(bottom: 10.w, top: 10.w),
      child: Text(title,
        style: TextStyle(
          color: Utils.hexToColor('#676767'), 
          fontSize: 12,
          height: 1
        ),
      ),
    );
  }

  Widget _buildCard() {
    List<Widget> content = [];
    List list = [
      {"title": '仓库'},
      {"title": '仓库'},
      {"title": '仓库'},
      {"title": '仓库'},
      {"title": '仓库'},
      {"title": '仓库'},
      {"title": '仓库'},
      {"title": '仓库'},
    ];

    for(var item in list) {
      content.add(
        Container(
          width: 140.w,
          height: 76.w,
          alignment: Alignment.center,
          color: Utils.hexToColor('#F8F8F8'),
          child: Text(item['title'],
            style: TextStyle(color: Utils.hexToColor('#676767'), fontSize: 12), 
          ),
        )
      );
    }

    return Wrap(
      spacing: 10.w,
      runSpacing: 10.w,
      crossAxisAlignment: WrapCrossAlignment.start,
      children: content,
    );
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);

    return Container(
      child: Column(
        children: <Widget>[
          _buildCardTitle(widget.title),
          _buildCard(),
          _buildCardLine()
        ],
      ),
    );
  }
}